package veterinaria.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import veterinaria.excepcion.DAOExcepcion;
import veterinaria.modelo.FacturaCliente;
import veterinaria.util.ConexionBD;

public class FacturaClienteDAO extends BaseDAO {
	
	public Collection<FacturaCliente> listar() throws DAOExcepcion {
		Collection<FacturaCliente> c = new ArrayList<FacturaCliente>();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			con = ConexionBD.obtenerConexion();
			String query = "select idFactura,Cliente_idCliente,feFactura,mtTotal from factura where cliente_idCliente = 2 order by idFactura";
			stmt = con.prepareStatement(query);
			rs = stmt.executeQuery();
			while (rs.next()) {
				FacturaCliente vo = new FacturaCliente();
				vo.setIdFactura(rs.getInt("idFactura"));
				vo.setCliente_idCliente(rs.getInt("Cliente_idCliente"));
				vo.setFeFactura(rs.getDate("feFactura"));
				vo.setMtTotal(rs.getDouble("mtTotal"));	
				c.add(vo);
			}

		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarResultSet(rs);
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
		return c;
	}
}
